package com.handpay.nocardpay.baselibrary.recommendercod.presenter;

import android.content.Context;

import com.handpay.nocardpay.baselibrary.commbase.model.IBaseModel;
import com.handpay.nocardpay.baselibrary.commbase.model.bean.BaseErrorInfo;
import com.handpay.nocardpay.baselibrary.recommendercod.model.RecommenderCodeModelImpl;
import com.handpay.nocardpay.baselibrary.recommendercod.model.bean.RecommenderCodeBean;
import com.handpay.nocardpay.baselibrary.recommendercod.view.IRecommenderCodeView;

import java.util.HashMap;

/**
 * Created by lyang on 2017/8/18.
 */

public class RecommenderCodePresenter implements IBaseModel.OnRequestFinishedListener<RecommenderCodeBean> {
    private IRecommenderCodeView mRecommenderCodeView;
    private RecommenderCodeModelImpl mRecommenderCodeModelImpl;

    public RecommenderCodePresenter(Context context, IRecommenderCodeView view) {
        this.mRecommenderCodeModelImpl = new RecommenderCodeModelImpl(context);
        this.mRecommenderCodeView = view;
    }

    public void getRecommenderCode(HashMap<String, Object> paramers, Class<RecommenderCodeBean> clzz, boolean isShowLoading) {
        if (mRecommenderCodeView != null) {
            if (isShowLoading) {
                mRecommenderCodeView.showProgress();
            }
        }
        mRecommenderCodeModelImpl.request(paramers, clzz, this);
    }

    @Override
    public void onError(BaseErrorInfo baseErrorInfo) {
        if (mRecommenderCodeView != null) {
            mRecommenderCodeView.hideProgress();
            mRecommenderCodeView.showErrorAlert(baseErrorInfo);
        }
    }

    @Override
    public void onSuccess(RecommenderCodeBean response) {
        if (mRecommenderCodeView != null) {
            mRecommenderCodeView.hideProgress();
            mRecommenderCodeView.setRecommenderCode(response);
        }
    }
}